<template>
	<view class="page" :data-theme="themeStyle">
		<view v-for="(item, index) in diyData.value" :key="index">
			<template v-if="item.controller == 'GoodsCategory'">
				<!-- 商品分类 -->
				<!-- :bottom="iphoneX?90:55" -->
				<view :class="iphoneX ? 'active' : 'no'">
					<diy-goods-level-category :value="item" @netFinish="netFinish" :bottom="windowHeight" :autoHeight="!1" ref="goodsLevelCategory"></diy-goods-level-category>
				</view>
			</template>
		</view>
		<loading-cover ref="loadingCover"></loading-cover>
		<!-- 底部tabBar -->
		<diy-bottom-nav type="shop"></diy-bottom-nav>
	</view>
</template>

<script>
import diyGoodsLevelCategory from '@/components/diy-goods-level-category/diy-goods-level-category.vue';
import diyBottomNav from '@/components/diy-bottom-nav/diy-bottom-nav.vue';
import globalConfig from '@/common/js/golbalConfig.js';
export default {
	components: {
		diyBottomNav,
		diyGoodsLevelCategory
	},
	data() {
		return {
			diyData: [],
			iphoneX: false,
			windowHeight: ''
		};
	},
	mixins: [globalConfig],
	onLoad() {
		uni.hideTabBar();
		this.iphoneX = this.$util.uniappIsIPhoneX();
		this.getDiyInfo();
	},
	onShow() {
		this.$langConfig.refresh();
		this.getHeight();
		this.getDiyInfo();
		if(this.$refs.goodsLevelCategory) this.$refs.goodsLevelCategory[0].getCartData();
	},
	methods: {
		getHeight(){
			var self = this;
			uni.getSystemInfo({
				success: function (res) {
					self.windowHeight = res.windowHeight - 57;
					if(self.iphoneX){
						self.windowHeight = self.windowHeight -33;
					}
				}
			});
		},	
		//监听子组件分类列表是否请求完成
		netFinish(e) {
			if (e) {
				if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
			}
			setTimeout(() => {
				if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
			}, 1000);
		},
		getDiyInfo() {
			this.$api.sendRequest({
				url: '/api/diyview/info',
				data: {
					name: 'DIYVIEW_GOODS_CATEGORY'
				},
				success: res => {
					console.log("fenlei")
					if (res.code != 0 || !res.data) {
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
						return;
					}
					this.diyData = res.data;

					if (this.diyData.value) {
						this.diyData = JSON.parse(this.diyData.value);
					}
					uni.stopPullDownRefresh();
				},
				fail: res => {}
			});
		}
	}
};
</script>

<style lang="scss">
	/deep/ .uni-popup__wrapper.uni-center{
		background: rgba(0,0,0,0.6);
	}
	/deep/.uni-popup__wrapper.uni-custom.center .uni-popup__wrapper-box{
		border-radius: 10px;
		background: rgba($color: #000000, $alpha: 0);
	}
	/deep/ .uni-popup__wrapper.uni-custom.center .uni-popup__wrapper-box{
		overflow-y: visible;
	}
</style>
